<template>
  <div class="blog-post">
    <van-field v-model="title" label="标题" placeholder="请输入标题"/>
    <van-field
        v-model="content"
        label="内容"
        type="textarea"
        placeholder="请输入内容"
        rows="5"
    />
    <van-field
        v-model="imageUrl"
        label="图片"
        type="textarea"
        placeholder="请输入图片网址"
        rows="3"
    />
    <van-button type="primary" block @click="submitPost">发布博客</van-button>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue';
import request from "../../plugins/request.ts";
import {showSuccessToast} from "vant/es";
import {useRouter} from "vue-router";

const router = useRouter()
const title = ref('');
const content = ref('');
const imageUrl = ref('');

const submitPost = async () => {
  const result = await request.post("/blog/add", {
    "content": content.value,
    "imageUrl": imageUrl.value,
    "title": title.value,
  })
  if (result.data.code === 200) {
    showSuccessToast("发布成功")
    await router.replace("/nearby")
  }
};

</script>

<style scoped>
.blog-post {
  margin: 20px;
}
</style>
